home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16026 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using the %c control in SCANF
  5. Date: 9 Apr 1996 07:40:13 GMT
  6. Organization: systems hk
  7. Message-ID: <4kd48t$k1h@nadine.teleport.com>
  8. References: <4k9j02$fl9@arl-news-svc-5.compuserve.com>
  9. NNTP-Posting-Host: ip-pdx07-07.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. Philippe Verdy <100105.3120@compuserve.com> wrote:
  16. >> Can anyone please give me some examples of using the %c control in the 
  17. >> scanf function.
  18. [snip]
  19. >> Can anyone help me use the %c control properly? If not, do you know of a 
  20. >> better way of accomplishing this, perhaps with iostream.h functions instead?
  21. --------------
  22. >Your error is normal: with %s you read a line into textLine,
  23. >then with %c you read a character which should be stored in
  24. >the next variable. But you did not specify that variable as
  25. >an argument.
  26. >char textLine[MAXBUFFERSIZE], x;
  27. >scanf("%s%c", textLine, x);
  28. >Note that you must enter two lines prior to having results:
  29. >%s reads all until the end-of line. then %c returns the first
  30. >character of the next line entered.
  31. >
  32. [snip]
  33. --------------
  34. A couple of problems with the response:
  35.  
  36. scanf requires pointers as arguments, therefore it should read:
  37.  
  38.   scanf( "%s %c",textLine,&x );
  39.  
  40. Also, if there is whitespace after an contiguous stream of characters
  41. in the record, then I assume that '&x' will pick up the next
  42. character in the _same_ record.
  43.  
  44. Yours, Geoff Houck
  45.  
  46.